<template>
  <view class="container">
    <view class="header">
      <text class="title">我的银行卡</text>
      <button class="add-btn" @click="addBankCard">添加银行卡</button>
    </view>

    <view class="bank-list">
      <view class="bank-card" v-for="card in bankCards" :key="card.id" @click="selectCard(card)">
        <image class="bank-icon" :src="card.icon || '/static/bank/default.png'"></image>
        <view class="bank-info">
          <text class="bank-name">{{card.name}}</text>
          <text class="bank-number">尾号{{card.number.slice(-4)}}</text>
        </view>
        <uni-icons type="arrowright" size="20" color="#999"></uni-icons>
      </view>

      <view class="empty" v-if="bankCards.length === 0">
        <image src="/static/bank/empty.png" mode="aspectFit"></image>
        <text>暂无银行卡，请添加</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      bankCards: [
        {id: 1, name: '工商银行', number: '6212260200123456789', icon: '/static/bank/icbc.png'}
      ]
    }
  },
  methods: {
    addBankCard() {
      uni.navigateTo({
        url: '/pages/bank/add'
      })
    },
    selectCard(card) {
      const pages = getCurrentPages();
      const prevPage = pages[pages.length - 2];
      if (prevPage.route === 'pages/withdraw/withdraw') {
        prevPage.$vm.bankCard = card;
        uni.navigateBack();
      }
    }
  }
}
</script>

<style lang="scss">
.container {
  padding: 30rpx;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40rpx;
  
  .title {
    font-size: 40rpx;
    font-weight: bold;
    color: #333;
  }
  
  .add-btn {
    background: none;
    border: none;
    color: #007AFF;
    font-size: 28rpx;
    padding: 0;
  }
}

.bank-list {
  .bank-card {
    display: flex;
    align-items: center;
    padding: 30rpx;
    background: #fff;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
    
    .bank-icon {
      width: 60rpx;
      height: 60rpx;
      margin-right: 20rpx;
    }
    
    .bank-info {
      flex: 1;
      
      .bank-name {
        font-size: 32rpx;
        color: #333;
        margin-bottom: 10rpx;
      }
      
      .bank-number {
        font-size: 26rpx;
        color: #999;
      }
    }
  }
  
  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100rpx 0;
    
    image {
      width: 200rpx;
      height: 200rpx;
      margin-bottom: 30rpx;
    }
    
    text {
      font-size: 28rpx;
      color: #999;
    }
  }
}
</style>